package com.dq.domain.org;

import com.dq.domain.sys.user.user.BossUser;
import com.dq.vo.baseVo.VO;
import com.dq.domain.sys.section.SysSection;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ----
 * @date 2019/9/12 0012 11:54:32
 */
@Data
@Entity
@ApiModel("门店信息")
public class Org extends SysSection implements VO.ToVO {
    @ApiModelProperty("门店LOGO")
    protected String orgImg;
    protected String imgUrl;
    @ApiModelProperty("国家")
    protected String country = "中国";
    @ApiModelProperty("省份")
    protected String province;
    @ApiModelProperty("城市")
    protected String city;
    @ApiModelProperty("区县")
    protected String district;
    @ApiModelProperty("详细地址")
    protected String address;
    @ApiModelProperty("经度")
    @Column(columnDefinition="decimal(10,6) default 0.000000")
    protected BigDecimal lng;
    @ApiModelProperty("纬度")
    @Column(columnDefinition="decimal(10,6) default 0.000000")
    protected BigDecimal lat;

    @ApiModelProperty("联系电话")
    protected String contaceMobile;
    @ApiModelProperty("固定电话")
    protected String fixedPhone;

    @ApiModelProperty("店长")
    @ManyToOne
    protected BossUser shopManager;
//    @ApiModelProperty("所属省总")
//    @ManyToOne
//    protected BossUser provincialManager;

    @ApiModelProperty("门店总床位数")
    @Column(columnDefinition="int default 0")
    protected Long bedNum;


    @ApiModelProperty("法人姓名")
    protected String legalName;
    @ApiModelProperty("法人身份证号")
    protected String legalCardNo;
    @ApiModelProperty("法人身份证正面")
    protected String legalIdCardFrontPositive;
    @ApiModelProperty("法人身份证反面")
    protected String legalIdCardBackPositive;
    @ApiModelProperty("营业执照")
    protected String businessLicense;
    @ApiModelProperty("特殊行业证明")
    protected String specialProfessionProve;

    @ApiModelProperty(value = "审核时间")
    protected Long applyTime;
    @ApiModelProperty("审核失败原因")
    protected String failReason;


    @ApiModelProperty(value = "门店初始分享", hidden = true)
    @Transient
    protected String initialOrgQr;
    @ApiModelProperty("店长ID")
    @Transient
    protected Long shopManagerId;
    @ApiModelProperty("所属省总id")
    @Transient
    protected Long provincialManagerId;

    @Data
    @ApiModel(value = "门店视图")
    public static class Vo extends SysSection.Vo {
        @ApiModelProperty("id")
        protected Long id;
        @ApiModelProperty("门店编号")
        protected String sectionCode;
        @ApiModelProperty("门店简称")
        protected String simpleName;
        @ApiModelProperty("门店全称")
        protected String fullName;
        @ApiModelProperty(value = "排序")
        private Integer sort;
        @ApiModelProperty("经度")
        protected BigDecimal lng;
        @ApiModelProperty("纬度")
        protected BigDecimal lat;

        @ApiModelProperty("店长")
        protected Long shopManagerId;
        protected String shopManagerName;
        /** set 赋值 */
        @ApiModelProperty("所属省总")
        protected Long provincialManagerId;
        protected String provincialManagerName;
        /** set 赋值 */
        @ApiModelProperty("所属部门经理")
        protected Long departmentManagerId;
        protected String departmentManagerName;
        @ApiModelProperty(value = "上级部门")
        private Long parentId;
        private String parentSectionCode;
        private String parentSimpleName;
        private String parentFullName;

        @ApiModelProperty(value = "描述")
        private String description;
        @ApiModelProperty("修改时间")
        protected String lastModifyTime;
        @ApiModelProperty("创建者")
        protected String createUserName;
        @ApiModelProperty("修改人")
        protected String updateUserName;

        @ApiModelProperty("法人名称")
        protected String legalName;
        @ApiModelProperty("法人身份证号码")
        protected String legalCardNo;
        @ApiModelProperty("手机号")
        protected String contaceMobile;
        @ApiModelProperty("固定电话")
        protected String fixedPhone;

        @ApiModelProperty("门店地址")
        protected String address;
        @ApiModelProperty("门店地址")
        protected String orgAddress;
        @ApiModelProperty("开设时间")
        protected String createTime;

        @ApiModelProperty("门店状态")
        protected String statusEn;
        @ApiModelProperty("门店状态")
        protected String statusCn;
        @ApiModelProperty("门店LOGO")
        protected String orgImg;

        @ApiModelProperty("门店省份")
        protected String province;
        @ApiModelProperty("门店所在城市")
        protected String city;
        @ApiModelProperty("门店所在区")
        protected String district;
        @ApiModelProperty(value = "门店logo")
        protected String logoUrl;

        @ApiModelProperty("门店初始分享")
        protected String initialOrgQr;

        private List<SysSection.Vo> children = new ArrayList<>();

        @ApiModelProperty(value = "类型, 用户后台部门修改确定是否显示门店修改页面")
        private String updateType = "orgUpdate";

        protected String imgUrl;
    }


    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id=this.id;

        vo.sectionCode = this.getSectionCode();
        vo.simpleName = this.getSimpleName();
        vo.fullName = this.getFullName();

        vo.description = this.getDescription();
        vo.sort = this.getSort();
        vo.statusEn = this.status == null ? null : this.status.toString();
        vo.statusCn = this.status == null ? null : this.status.name;
        vo.lat = this.getLat();
        vo.lng = this.getLng();

        vo.shopManagerId = this.getShopManager() == null ? null : this.getShopManager().getId();
        vo.shopManagerName = this.getShopManager() == null ? "" : this.getShopManager().getUserRealcName();
//        vo.provincialManagerId = this.getProvincialManager() == null ? null : this.getProvincialManager().getId();
//        vo.provincialManagerName = this.getProvincialManager() == null ? "" : this.getProvincialManager().getUserRealcName();

        vo.parentId = this.getParent() == null ? 0 : this.getParent().getId();
        vo.parentSectionCode = this.getParent() == null ? "" : this.getParent().getSectionCode();
        vo.parentSimpleName = this.getParent() == null ? "" : this.getParent().getSimpleName();
        vo.parentFullName = this.getParent() == null ? "" : this.getParent().getFullName();

        vo.createTime = fmt(this.getCreateTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.lastModifyTime = fmt(this.getLastModifyTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.createUserName = this.getCreateUser() == null ? "" : this.getCreateUser().getUserRealcName();
        vo.updateUserName = this.getUpdateUser() == null ? "" : this.getUpdateUser().getUserRealcName();

        vo.legalName  = this.getLegalName();
        vo.contaceMobile = this.getContaceMobile();
        vo.legalCardNo = this.getLegalCardNo();
        vo.fixedPhone = this.getFixedPhone();
        vo.address = fmt(this.getAddress());
        vo.orgAddress = fmt(this.getProvince())+fmt(this.getCity())+fmt(this.getDistrict())+fmt(this.getAddress());
        vo.orgImg = fmt(this.getOrgImg());

        vo.province = fmt(this.getProvince());
        vo.city = fmt(this.getCity());
        vo.district = fmt(this.getDistrict());
        vo.logoUrl = fmt(this.orgImg);
        vo.imgUrl = this.getImgUrl();
        return vo;
    }
}
